﻿using cfg.item;
using UnityEngine;

namespace QFramework.Monk
{
    public class GenerateItemSystem:AbstractSystem
    {
        private ConfigModel configModel;
        protected override void OnInit()
        {
            configModel= this.GetModel<ConfigModel>();
            
        }
        
        public void GenerateItem(Vector3 pos,Item item)
        {
            if (GeneratorManager.Default==null)
            {
                return;
            }
            //以pos为圆心1为半径生成一个随机位置
            pos += new Vector3(Random.Range(-1, 1), Random.Range(-1, 1)) * 1;
            var precent = Random.Range(0, 1.0f);
            var dropPrent = 0f;
            switch (item.ItemType)
            {
                case ItemType.Exp:
                    dropPrent = AppStart.expDropPrecent.Value;
                    break;
                case  ItemType.Gold:
                    dropPrent = AppStart.coinDropPrecent.Value;
                    break;
                case ItemType.Hp:
                    dropPrent = AppStart.hpDropPrecent.Value;
                    break;
                case ItemType.Bomb:
                    dropPrent = AppStart.bombPrecent.Value;
                    break;
                case ItemType.GetAllExp:
                    dropPrent = AppStart.getAllExpPrecent.Value;
                    break;
            }
            if (precent<dropPrent)
            {
                //GeneratorManager.Default.GetAllExp.InstantiateWithParent(GeneratorManager.Default.transform).Position(pos).Show();
                GeneratorManager.Default.CreateDropItem(pos, item);
            }

        }
    }
}